package top.laoshuzi.designpatterns.base.created.factory.kotlin

/**
 * 产品工厂
 */
class ProductFactory {

    companion object {
        const val TYPE_PRODUCT_A: Int = 1
        const val TYPE_PRODUCT_B: Int = 2

        fun createProduct(productType: Int): Product {
            when (productType) {
                1 -> {
                    val product = ProductA()
                    product.setName("ProductA")
                    return product
                }
                2 -> {
                    val product = ProductB()
                    product.setName("ProductB")
                    return product
                }
                else -> throw NullPointerException("无效产品类型")
            }
        }
    }

}